package com.ruoyi.web.controller.shop.delivery;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.shop.delivery.domain.ShopFreight;
import com.ruoyi.shop.delivery.service.IShopFreightService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商城运费模板Controller
 * 
 * |----------------------------------------------------------------------|
 * |favorshop [简单好用，让您喜爱的小商城]
 * |----------------------------------------------------------------------|
 * |copyright www.favorshop.cn All rights reserved.
 * |----------------------------------------------------------------------|
 * | @author xuxiang
 * |----------------------------------------------------------------------|
 * | @date 2023-05-29
 * |----------------------------------------------------------------------|
 */
@Controller
@RequestMapping("/shop/freight")
public class ShopFreightController extends BaseController {

	private String prefix = "/shop/delivery/freight";

	@Autowired
	private IShopFreightService shopFreightService;

	@RequiresPermissions("shop:freight:view")
	@GetMapping()
	public String freight() {
		return prefix + "/freight";
	}

	/**
	 * 查询商城运费模板列表
	 */
	@RequiresPermissions("shop:freight:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ShopFreight shopFreight) {
		startPage();
		List<ShopFreight> list = shopFreightService.selectFreightList(shopFreight);
		return getDataTable(list);
	}

	/**
	 * 导出商城运费模板列表
	 */
	@RequiresPermissions("shop:freight:export")
	@Log(title = "商城运费模板", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(ShopFreight shopFreight) {
		List<ShopFreight> list = shopFreightService.selectFreightList(shopFreight);
		ExcelUtil<ShopFreight> util = new ExcelUtil<ShopFreight>(ShopFreight.class);
		return util.exportExcel(list, "商城运费模板数据");
	}

	/**
	 * 新增商城运费模板
	 */
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存商城运费模板
	 */
	@RequiresPermissions("shop:freight:add")
	@Log(title = "商城运费模板", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ShopFreight shopFreight) {
		return toAjax(shopFreightService.insertFreight(shopFreight));
	}

	/**
	 * 修改商城运费模板
	 */
	@RequiresPermissions("shop:freight:edit")
	@GetMapping("/edit/{freightId}")
	public String edit(@PathVariable("freightId") Long freightId, ModelMap mmap) {
		ShopFreight shopFreight = shopFreightService.selectByFreightId(freightId);
		mmap.put("freight", shopFreight);
		return prefix + "/edit";
	}

	/**
	 * 修改保存商城运费模板
	 */
	@RequiresPermissions("shop:freight:edit")
	@Log(title = "商城运费模板", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ShopFreight shopFreight) {
		return toAjax(shopFreightService.updateFreight(shopFreight));
	}

	/**
	 * 删除商城运费模板
	 */
	@RequiresPermissions("shop:freight:remove")
	@Log(title = "商城运费模板", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(shopFreightService.deleteByFreightIds(ids));
	}
}
